package mylibrary.string;

import java.io.UnsupportedEncodingException;

public class Test {

	public static void main(String[] args) throws UnsupportedEncodingException {
		
		String s2 = "你们123你好";
//		System.out.println(s2.getBytes("ISO-8859-1").length);
		
		String s1 = "人";
//		System.out.println(s1.getBytes().length);
//		System.out.println(s1.length());
		
		
		
		String s = "Hello！你好！";
		
		byte[] bytesISO8859 = null;
		byte[] bytesGBK = null;
		
		try {
			bytesISO8859 = s.getBytes("iso-8859-1");
			bytesGBK = s.getBytes("GBK");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		System.out.println("*********88\n 8859 bytes");
		System.out.println("byte is " + arrayToString(bytesISO8859));
		System.out.println("hex format is " + encodeHex(bytesISO8859));
		
		
	}
	
	private static String encodeHex(byte[] bytes) {
		StringBuffer sb = new StringBuffer(bytes.length * 2);
		String re;
		for(byte b:bytes) {
			re = Integer.toHexString(b);
			sb.append(re.length()>2?re.substring(6, 8):b);
			sb.append(" ");
		}
		return sb.toString();
		
	}
	
	private static String arrayToString(byte[] bytes) {
		StringBuffer sb = new StringBuffer();
		for(byte b:bytes) {
			sb.append(b+" ");
		}
		return sb.toString();
	}
}
